/**
 * @Copyright:Copyright (c) 2007 - 2023
 */
package com.tengtong.duang.app.query.core;

import com.tengtong.commons.lang.StringUtils;

/**
 * 常量库
 *
 * @author lin_jinming
 * @since: v1.0
 */
public final class QueryConstants {

    /**
     * 布尔操作
     *
     *
     * @author lin_jinming
     * @since: v1.0
     */
    public static enum BooleanOp {
        OR,
        
        AND,
        
        NOT
        ;
        
        public static BooleanOp ofObject(Object v) {
            if(v == OR) {
                return OR;
            }
            if(v == AND) {
                return AND;
            }
            if(v == NOT) {
                return NOT;
            }
            return null;
        }
        
        public static BooleanOp fromValue(String v) {
            if(StringUtils.equalsIgnoreCase(v, "or")) {
                return OR;
            }
            
            if(StringUtils.equalsIgnoreCase(v, "and")) {
                return AND;
            }
            
            if(StringUtils.equalsIgnoreCase(v, "not")) {
                return NOT;
            }
            
            return null;
        }
        
        public static boolean check(Object o) {
            if(o == OR || o == AND || o == NOT) {
                return true;
            }
            return false;
        }
    }
    
    /**
     * 支持的函数与操作名称
     *
     *
     * @author lin_jinming
     * @since: v1.0
     */
    public static enum FunctionNames {
        Eq("="),
        
        NEq("<>"),
        
        LT("<"),
        
        LE("<="),
        
        GT(">"),
        
        GE(">="),
        
        Like(""),
        
        EndWith(""),
        
        StartWith(""),
        
        In(""),
        
        NotIn("")
        ;
        
        private String op;
        
        /**
         * 
         */
        private FunctionNames(String o) {
            this.op = o;
        }

        /**
         * @return the op
         */
        public String getOp() {
            return op;
        }
        
        public static FunctionNames fromValue(String v) {
            for(var o: values()) {
                if(StringUtils.equalsIgnoreCase(v, o.name())) {
                    return o;
                }
            }
            return null;
        }
        
    }
    
}
